package com.api.shopapi.mapper;


import com.api.shopapi.entity.CartGoods;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CartGoodsMapper {

    @Insert("insert into cart_goods" +
            "(" +
            "CartGoodsCode," +
            "CartBusinessCode," +
            "GoodsCode," +
            "Number," +
            "CreateTime," +
            "PlanTime," +
            "Available"+
            ")" +
            "values" +
            "(" +
            "#{cartGoods.CartGoodsCode}," +
            "#{cartGoods.CartBusinessCode}," +
            "#{cartGoods.GoodsCode}," +
            "#{cartGoods.Number}," +
            "#{cartGoods.CreateTime}," +
            "#{cartGoods.PlanTime}," +
            "#{cartGoods.Available}" +
            ")")
    public int insert(@Param("cartGoods") CartGoods cartGoods);

    @Update("update cart_goods set " +
            "CartBusinessCode = #{cartGoods.CartBusinessCode}," +
            "GoodsCode=#{cartGoods.GoodsCode}," +
            "Number=#{cartGoods.Number}," +
            "CreateTime=#{cartGoods.CreateTime}," +
            "PlanTime=#{cartGoods.PlanTime}," +
            "Available=#{cartGoods.Available}" +
            " where CartGoodsCode=#{cartGoods.CartGoodsCode}")
    public int update(@Param("cartGoods") CartGoods cartGoods);

    @Delete("delete from cart_goods where CartGoodsCode=#{cartGoodsCode}")
    public int delete(@Param("cartGoodsCode") String cartGoodsCode);

    @Select("select * from cart_goods order by CreateTime desc")
    public List<CartGoods> getList();

    @Select("select * from cart_goods where CartGoodsCode=#{cartGoodsCode} limit 1")
    public CartGoods getByCartGoodsCode(@Param("cartGoodsCode") String cartGoodsCode);


    @Select("select * from cart_goods where cartBusinessCode=#{cartBusinessCode}")
    public List<CartGoods> getListByCartBusinessCode(String cartBusinessCode);

    @Select("select * from cart_goods where goodsCode=#{goodsCode}")
    List<CartGoods> getListByGoodsCode(String goodsCode);


}
